package com.bwie.redkids.adapter;

import java.util.ArrayList;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bwie.redkids.R;
import com.bwie.redkids.bean.Class_gv_Bean.Productlist;
import com.lidroid.xutils.BitmapUtils;

public class ClassifyGridViewBaseAdapter extends BaseAdapter {

	private ArrayList<Productlist> arrayList2;
	private Context context;

	public ClassifyGridViewBaseAdapter(Context context,
			ArrayList<Productlist> arrayList2) {
		this.context = context;
		this.arrayList2 = arrayList2;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return arrayList2.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return arrayList2.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder = null;
		if (convertView == null) {
			holder = new ViewHolder();
			convertView = View.inflate(context, R.layout.classify_grid_item,
					null);
			holder.iv_classify = (ImageView) convertView
					.findViewById(R.id.iv_classify);
			holder.tv_classify = (TextView) convertView
					.findViewById(R.id.tv_classify);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		BitmapUtils bitmapUtils = new BitmapUtils(context);
		bitmapUtils.display(holder.iv_classify, arrayList2.get(position).pic);
		holder.tv_classify.setText(arrayList2.get(position).name);
		return convertView;
	}

	class ViewHolder {
		ImageView iv_classify;
		TextView tv_classify;
	}

}
